package org.myorg.datastraemapi.demo;


import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.myorg.datastraemapi.model.Student;

import java.util.ArrayList;
import java.util.List;

public class FilterDemo {

	public static void main(String[] args) throws Exception {
		final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

		List<Student> listSource = new ArrayList<Student>() {{
			add(new Student(1, 1));
			add(new Student(2, 2));
			add(new Student(3, 3));
			add(new Student(4, 4));
			add(new Student(5, 4));
			add(new Student(6, 4));
			add(new Student(7, 4));
		}};
		DataStreamSource<Student> dataStreamSource = env.fromCollection(listSource);

		SingleOutputStreamOperator<Student> filter = dataStreamSource.filter(new FilterFunction<Student>() {
			@Override
			public boolean filter(Student student) throws Exception {
				if (student.id > 2) {
					return true;
				}
				return false;
			}
		});
		filter.print();

		env.execute("Flink Streaming Java API Skeleton");
	}
}
